home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TUTOROOT.PAK / STEP03.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  75 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1994 by Borland International
  3. //   Tutorial application -- step03.cpp
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/framewin.h>
  8. #include <owl/dc.h>
  9. #include <string.h>
  10.  
  11. class TDrawWindow : public TWindow {
  12.   public:
  13.     TDrawWindow(TWindow* parent = 0);
  14.  
  15.   protected:
  16.     // Override member function of TWindow
  17.     bool CanClose();
  18.  
  19.     // Message response functions
  20.     void EvLButtonDown(uint, TPoint&);
  21.     void EvRButtonDown(uint, TPoint&);
  22.  
  23.   DECLARE_RESPONSE_TABLE(TDrawWindow);
  24. };
  25.  
  26. DEFINE_RESPONSE_TABLE1(TDrawWindow, TWindow)
  27.   EV_WM_LBUTTONDOWN,
  28.   EV_WM_RBUTTONDOWN,
  29. END_RESPONSE_TABLE;
  30.  
  31. TDrawWindow::TDrawWindow(TWindow* parent)
  32. {
  33.   Init(parent, 0, 0);
  34. }
  35.  
  36. bool
  37. TDrawWindow::CanClose()
  38. {
  39.   return MessageBox("Do you want to save?", "Drawing has changed",
  40.                     MB_YESNO | MB_ICONQUESTION) == IDNO;
  41. }
  42.  
  43. void
  44. TDrawWindow::EvLButtonDown(uint, TPoint& point)
  45. {
  46.   char s[16];
  47.   TClientDC dc(*this);
  48.  
  49.   wsprintf(s, "(%d,%d)", point.x, point.y);
  50.   dc.TextOut(point, s, strlen(s));
  51. }
  52.  
  53. void
  54. TDrawWindow::EvRButtonDown(uint, TPoint&)
  55. {
  56.   Invalidate();
  57. }
  58.  
  59. class TDrawApp : public TApplication {
  60.   public:
  61.     TDrawApp() : TApplication() {}
  62.  
  63.     void InitMainWindow()
  64.     {
  65.       SetMainWindow(new TFrameWindow(0, "Sample ObjectWindows Program",
  66.         new TDrawWindow));
  67.     }
  68. };
  69.  
  70. int
  71. OwlMain(int /*argc*/, char* /*argv*/ [])
  72. {
  73.   return TDrawApp().Run();
  74. }
  75.